﻿using Appliaction.Dto.DB;
using Appliaction.IAppServices.DB;
using AutoMapper;
using Domain.Entitys.DB;
using Domain.IRepositorys.DB;
using Microsoft.Identity.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.DB
{
    public class Db_MeasureService:IDb_MeasureService
    {
        private readonly IDb_MeasureRepository db_MeasureRepository;
        private readonly IMapper mapper;

        public Db_MeasureService(IDb_MeasureRepository db_MeasureRepository, IMapper mapper)
        {
            this.db_MeasureRepository = db_MeasureRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 查询总条数
        /// </summary>
        /// <param name="Measure_code">编码</param>
        /// <param name="Measure_name">昵称</param>
        /// <returns></returns>
        public int Db_MeasureCount(string Measure_code, string Measure_name)
        {
            return db_MeasureRepository.Db_MeasureCount(Measure_code, Measure_name);
        }

        /// <summary>
        /// 添加计量单位
        /// </summary>
        /// <param name="db_MeasureAddDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> Db_MeasureAdd(Db_MeasureAddDto db_MeasureAddDto)
        {
            Db_Measure db = mapper.Map<Db_Measure>(db_MeasureAddDto);
            return await db_MeasureRepository.Db_MeasureAdd(db);
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="db_MeasureDeleteDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> Db_MeasureDelete(Db_MeasureDeleteDto db_MeasureDeleteDto)
        {
            Db_Measure db = mapper.Map<Db_Measure>(db_MeasureDeleteDto);
            return await db_MeasureRepository.Db_MeasureDelete(db);
        }

        /// <summary>
        /// 修改计量单位
        /// </summary>
        /// <param name="db_MeasureUpdateDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> Db_MeasureUpdate(Db_MeasureUpdateDto db_MeasureUpdateDto)
        {
            Db_Measure db = mapper.Map<Db_Measure>(db_MeasureUpdateDto);
            return await db_MeasureRepository.Db_MeasureUpdate(db);
        }

        /// <summary>
        /// 分页查询、条件查询
        /// </summary>
        /// <param name="Measure_code">编码</param>
        /// <param name="Measure_name">昵称</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">查几条</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<Db_Measure> SelectDb_MeasureFYWHERE(string Measure_code, string Measure_name, int currentPage, int pageSize)
        {
            return db_MeasureRepository.SelectDb_MeasureFYWHERE(Measure_code, Measure_name, currentPage, pageSize);
        }
    }
}
